/*
Copyright(c) 2008 Jari Kemppinen <jari@viddem.com>

This example was built upon the PureMVC Framework by Cliff Hall.
http://www.puremvc.org
This example uses the Java PureMVC Framework Version 0.2

Please contribute to the PureMVC community.

License
-------
Your reuse is governed by the Creative Commons Attribution 3.0 license.
 */

package org.lbroussal.client.view;

import org.lbroussal.client.ApplicationFacade;
import org.lbroussal.client.model.ItemDataProxy;
import org.lbroussal.client.view.components.MainScreen;
import org.puremvc4gwt.client.interfaces.INotification;
import org.puremvc4gwt.client.patterns.mediator.Mediator;

public class MainScreenMediator extends Mediator<ApplicationFacade> {

    public static final String NAME = "MainScreenMediator";

    private MainScreen mainScreen = null;

    public MainScreenMediator() {
        super(NAME, null, ApplicationFacade.MAIN,
                ApplicationFacade.LOGIN_SUCCESSFUL);
    }

    private MainScreen getMainScreen(ItemDataProxy itemProxy) {
        if (mainScreen == null)
            mainScreen = new MainScreen(this  , itemProxy);
        return mainScreen;
    }

    public void EXIT() {
        ApplicationFacade.loginDemo.exitApp();
    }

    public void LOGOUT() {
        this.notifyObservers(ApplicationFacade.PROCESS_LOGOUT);
        // todo is this not acceptable? new ProcessLogout().doLogout();
    }

    public void handleNotification(INotification note) {

        if (note.getName().equals(ApplicationFacade.LOGIN_SUCCESSFUL)) {
            onLoginSuccessful();
        }
    }

    private void onLoginSuccessful() {
        ApplicationFacade.loginDemo.setCurrentDisplay(getMainScreen(facade.getItemDataScope()));
    }
    

    
}